/* localStorage操作 */
// #region
/**
 * @description 获取localStorage
 * @param {String} key Storage名称
 * @returns {String}
 */
export function localGet(key: string) {
  const value = window.localStorage.getItem(key);
  try {
    return JSON.parse(window.localStorage.getItem(key) as string);
  } catch (error) {
    return value;
  }
}

/**
 * @description 存储localStorage
 * @param {String} key Storage名称
 * @param {*} value Storage值
 * @returns {void}
 */
export function localSet(key: string, value: any) {
  window.localStorage.setItem(key, JSON.stringify(value));
}

/**
 * @description 清除localStorage
 * @param {String} key Storage名称
 * @returns {void}
 */
export function localRemove(key: string) {
  window.localStorage.removeItem(key);
}

/**
 * @description 清除所有localStorage
 * @returns {void}
 */
export function localClear() {
  window.localStorage.clear();
}
// #endregion

/* sessionStorage操作 */
// #region
/**
 * @description 获取sessionStorage
 * @param {String} key Storage名称
 * @returns {String}
 */
export function sessionGet(key: string) {
  const value = window.sessionStorage.getItem(key);
  try {
    return JSON.parse(window.sessionStorage.getItem(key) as string);
  } catch (error) {
    return value;
  }
}

/**
 * @description 存储sessionStorage
 * @param {String} key Storage名称
 * @param {*} value Storage值
 * @returns {void}
 */
export function sessionSet(key: string, value: any) {
  window.sessionStorage.setItem(key, JSON.stringify(value));
}

/**
 * @description 清除sessionStorage
 * @param {String} key Storage名称
 * @returns {void}
 */
export function sessionRemove(key: string) {
  window.sessionStorage.removeItem(key);
}

/**
 * @description 清除所有sessionStorage
 * @returns {void}
 */
export function sessionClear() {
  window.sessionStorage.clear();
}
// #endregion
